/**
 * Created by gaoyj on 2018/6/30.
 */
window.onload = function (ev) {
    topbar.hide();
};

$('#dataTable').bootstrapTable({
    url: '/UserController/queryRegisterBlackList',
    height: $(window).height() - 200,
    pageSize: 30,
    pageList: [30, 50, 100],
    clickToSelect: true,
    // singleSelect: true,
    queryParams: queryParams,
    queryParamsType: '',
    sidePagination: 'server',
    responseHandler: function (res) {
        return {
            "rows": res   //数据
        };
    },
    columns: [
        {
            width: '30px',
            checkbox: true
        },
        {
            width: '30px',
            align: 'center',
            formatter: function (v, row, index) {
                return index + 1
            }
        }, {
            title: '被禁信息 ',
            field: 'data',
            width: '200px',
            align: 'center', formatter: function (v, o) {
                return o.data.replace("SUP_RIP", "").replace("SUP_RNO", "");
            }
        }
    ]
})
$("#search").click(function () {
    $("#dataTable").bootstrapTable("refresh");
});

$("#removeBlackList").click(function () {
    // var rows = $('#dataTable').bootstrapTable("getSelections");
    // if (rows == null || rows.length === 0) {
    //     layer.msg("请选择要操作的数据");
    //     return;
    // }
    if($("#accountOrIp").val()==""){
        layer.msg("请输入ip")
        return;
    }
    var type=$("#type").val();
    $.ajax({
        type: "post",
        url: '/UserController/removeBlackList',
        traditional: true,
        data: {
            data:type+ $("#accountOrIp").val()
        },
        success: function (data) {
            if (data.success) {
                $("#dataTable").bootstrapTable("refresh");
                layer.msg(data.message)
            } else {
                layer.msg(data.message)
            }
        }
    });
})
$("#createIpBlack").click(function () {
    $("#ip").val("");
    console.log("1")
    $("#ipBlackModal").modal({backdrop: 'static', keyboard: false});
})


$("#createIpBlackSubmit").click(function () {
    $.ajax({
        type: "post",
        url: 'UserController/createIpBlack',
        data: $("#ipBlackFrom").serialize(),
        dataType: "json",
        async: false,
        cache: false,
        success: function (data) {
            if (data.success) {
                $("#dataTable").bootstrapTable("refresh");
                $("#ipBlackModal").modal("hide");
                layer.msg('操作成功');
            } else {
                layer.msg(data.message)
            }
        }
    });
})
//下载
$("#export").click(function () {
    if ($("#accountOrIp").val() == "") {
        layer.msg("请输入ip")
        return
    }
    window.location.href = "/UserController/downloadUserInfoList?" + $("#ipQueryFrom").serialize()
})

function queryParams(params) {
    return {
        size: params.pageSize,
        page: params.pageNumber,
        accountOrIp: $("#accountOrIp").val(),
        type: $("#type").val()
    };
}




